<?php
	function getProducts(){
		global $db;
		$query = 'SELECT * FROM menu';
		$statement = $db->prepare($query);
		$statement->execute();
		$products = $statement->fetchAll();
		
		return $products;
	}

	function getProductsFromCategory($id){
		global $db;	
		$query = 'SELECT * FROM menu WHERE category = :id';
		$statement = $db->prepare($query);
		$statement->bindValue(':id',$id);
		$statement->execute();
		$products = $statement->fetchAll();
		
		return $products;
	}
	
	function getProductsNames(){
		global $db;
		$query = 'SELECT `name`FROM menu';
		$statement = $db->prepare($query);
		$statement->execute();
		$products = $statement->fetchAll();
		
		return $products;
	}
	
	function getProductName($product_id){
		global $db;
		$query = "SELECT `name`FROM menu WHERE id = $product_id";
		$statement = $db->prepare($query);
		$statement->execute();
		$products = $statement->fetchAll();
		
		return $products;
	}
	
	function deleteProduct($product_id){
		global $db;
		$query = "DELETE FROM menu WHERE id = $product_id";
		$db->exec($query);
	}
	
	function addProduct($category_id, $name, $description, $price){
		global $db;

		$query = "INSERT INTO menu (name, category, description, price) VALUES (:name, :category_id, :description, :price)";
		$statement = $db->prepare($query);
		$statement->bindValue(':name', filter_var($name,FILTER_SANITIZE_STRING));
		$statement->bindValue(':category', filter_var($category_id,FILTER_SANITIZE_INT));
		$statement->bindValue(':description', filter_var($description,FILTER_SANITIZE_STRING));
		$statement->bindValue(':name', filter_var($price,FILTER_SANITIZE_FLOAT));

		$statement->execute();
	}
?>